﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using WindowsGame.Data;
using WindowsGame.Enums;
using WindowsGame.GameObjects;

namespace WindowsGame.Manager
{
	public interface ISpriteManager
	{
		void LoadData(SnakeData[] snakeData, GameSize size, Int32 width, Int32 height);
		void Reset();
		void Update(GameTime gameTime);
		void Draw();
	}

	public class SpriteManager : ISpriteManager
	{
		private IList<Sprite> sprites;

		public SpriteManager()
		{
			sprites = new List<Sprite>();
		}

		public void LoadData(SnakeData[] snakeData, GameSize gameSize, Int32 width, Int32 height)
		{
			Int32 noCols = width / (8 * (Int32)gameSize);
			Int32 noRows = height / (8 * (Int32)gameSize);

			sprites.Clear();
			foreach (SnakeData data in snakeData)
			{
				Sprite sprite = new Sprite(data, gameSize, noCols, noRows);
				sprites.Add(sprite);
			}
		}

		public void Reset()
		{
			foreach (Sprite sprite in sprites)
			{
				sprite.Reset();
			}
		}
		public void Update(GameTime gameTime)
		{
			foreach (Sprite sprite in sprites)
			{
				sprite.Update(gameTime);
			}
		}

		public void Draw()
		{
			foreach (Sprite sprite in sprites)
			{
				sprite.Draw();
			}
		}
	}
}